import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-03-30
 * Time: 14:54
 */
public class RedisDemoHash {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("hset 和 hget的使用");
            jedis.flushAll();

            jedis.hset("key1","f1","11");
            HashMap<String,String> map = new HashMap<>();
            map.put("f2","22");
            map.put("f3","33");
            jedis.hset("key1",map);

            String result = jedis.hget("key1","f1");
            System.out.println("result: " + result);

            result = jedis.hget("key1","f2");
            System.out.println("result: " + result);


            result = jedis.hget("key1","f3");
            System.out.println("result: " + result);

            result = jedis.hget("key1","f4");
            System.out.println("result: " + result);

        }*/


        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("hexists 的使用");
            jedis.flushAll();

            jedis.hset("key1","f1","11");
            HashMap<String,String> map = new HashMap<>();
            map.put("f2","22");
            map.put("f3","33");
            jedis.hset("key1",map);

            boolean result = jedis.hexists("key1","f1");
            System.out.println("result: " + result);

            result = jedis.hexists("key1","f1111");
            System.out.println("result: " + result);

        }*/

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("hdel 的使用");
            jedis.flushAll();

            jedis.hset("key1","f1","11");
            HashMap<String,String> map = new HashMap<>();
            map.put("f2","22");
            map.put("f3","33");
            jedis.hset("key1",map);

            long result = jedis.hdel("key1","f1");
            System.out.println("result: " + result);

            result = jedis.hdel("key1","f2","f3");
            System.out.println("result: " + result);

            result = jedis.hdel("key1","f1111");
            System.out.println("result: " + result);

        }*/

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("hkeys 和 hvals 的使用");
            jedis.flushAll();

            jedis.hset("key1","f1","11");
            HashMap<String,String> map = new HashMap<>();
            map.put("f2","22");
            map.put("f3","33");
            jedis.hset("key1",map);

            Set<String> result = jedis.hkeys("key1");
            System.out.println("result: " + result);

            List<String> result1 = jedis.hvals("key1");
            System.out.println("result1: " + result1);
        }*/


        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("hmset 和 hmget 的使用");
            jedis.flushAll();

            HashMap<String,String> map = new HashMap<>();
            map.put("f1","11");
            map.put("f2","22");
            map.put("f3","33");
            jedis.hmset("key1",map);

            List<String> result = jedis.hmget("key1","f1","f2","f3");
            System.out.println("result: " + result);

        }*/

        try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("hmset 和 hmget 的使用");
            jedis.flushAll();

            HashMap<String,String> map = new HashMap<>();
            map.put("f1","11");
            map.put("f2","22");
            map.put("f3","33");
            jedis.hmset("key1",map);

            List<String> result = jedis.hmget("key1","f1","f2","f3");
            System.out.println("result: " + result);

        }


    }
}
